package com.ard.camera.demos.entry;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class DvrHostEntry {
    private String dvrIp;        // 硬盘录像机IP
    private String hostAddress;  // 监控主机地址
    private String hostName;     // 监控主机名称

    /**
     * 从字符串解析硬盘录像机主机条目
     * 格式：主机地址:主机名称 或 主机地址
     */
    public static DvrHostEntry fromString(String line, String dvrIp) {
        line = line.trim();
        if (line.contains(":")) {
            String[] parts = line.split(":", 2);
            String address = parts[0].trim();
            String name = parts[1].trim();
            return new DvrHostEntry(dvrIp, address, name);
        } else {
            return new DvrHostEntry(dvrIp, line, line);
        }
    }

    @Override
    public String toString() {
        if (hostAddress.equals(hostName)) {
            return hostAddress;
        }
        return hostAddress + ":" + hostName;
    }
}